package kr.saeildamil.androidstudy_second.ani;

import kr.saeildamil.androidstudy_second.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class AnimSet extends Activity {
	ImageView mAnimTarget;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_animset);
	
		mAnimTarget = (ImageView) findViewById(R.id.animtarget);
	
	}
	
	public void mOnClick(View v){
		AnimationSet ani = null;
		switch(v.getId()){
		case R.id.btnstart:
			ani = new AnimationSet(true);
			ani.setInterpolator(new LinearInterpolator());
			
			TranslateAnimation trans = new TranslateAnimation(
															Animation.RELATIVE_TO_PARENT, 0, 
															Animation.RELATIVE_TO_PARENT, 1, 
															Animation.RELATIVE_TO_PARENT, 0, 
															Animation.RELATIVE_TO_PARENT, 0);
			trans.setDuration(3000);
			ani.addAnimation(trans);
			
			AlphaAnimation alpha = new AlphaAnimation(1, 0);
			alpha.setDuration(300);
			alpha.setStartOffset(500);
			alpha.setRepeatCount(4);
			alpha.setRepeatMode(Animation.REVERSE);
			ani.addAnimation(alpha);
			break;
		}
		mAnimTarget.startAnimation(ani);
	}
}
